<?php
/**
 * 用户分销日志
 * author itholiday@126.com
 */
global $_W, $_GPC;
load()->func('tpl');
$html_title = $_W['current_module']['title'];
$op = !empty($_GPC['op']) ? $_GPC['op'] : 'list';
//页面显示条数
$pagesize = 20;
$page = max(1, $_GPC['page']);
$start = ($page - 1) * $pagesize;

$where = 'A.id > 0';

$keyword_fa = isset($_GPC['keyword_fa']) && !empty($_GPC['keyword_fa']) ? trim(input('keyword_fa')) : '';
$keyword_ch = isset($_GPC['keyword_ch']) && !empty($_GPC['keyword_ch']) ? trim(input('keyword_ch')) : '';
$order_id = isset($_GPC['order_id']) && !empty($_GPC['order_id']) ? trim(input('order_id')) : '';
$yong_type = isset($_GPC['yong_type']) ? trim(input('yong_type')) : '';
$start_time = isset($_GPC['start_time']) && !empty($_GPC['start_time']) ? strtotime($_GPC['start_time']) : '';
$end_time = isset($_GPC['end_time']) && !empty($_GPC['end_time']) ? strtotime($_GPC['end_time']) : '';

if (!empty($keyword_fa)){
    $where .= " and (A.user_id='$keyword_fa' or B.mobile='$keyword_fa' or B.truename like '%$keyword_fa%') ";
}

if (!empty($keyword_ch)){
    $where .= " and (A.sup_id='$keyword_ch' or C.mobile='$keyword_ch' or C.truename like '%$keyword_ch%') ";
}

if(strlen($yong_type)){
    $where .= " and A.yong_type='$yong_type' ";
}

if (!empty($order_id)){
    $where .= " and A.oid='$order_id' ";
}

if (!empty($start_time) && !empty($end_time)){
    $where .= " and A.create_time>=$start_time and A.create_time<=$end_time ";
} else {
    if (!empty($start_time)){
        $where .= " and A.create_time >= $start_time ";
    }
    if (!empty($end_time)){
        $where .= " and A.create_time <= $end_time ";
    }
}

if ($op == 'list' || $op == ''){
    $pagediv = "list";
    $total = pdo_fetchcolumn('SELECT COUNT(*) AS `number` FROM ' . tablename('yq_haircircle_user_fx_log') . 'A left join ims_yq_haircircle_users B on A.user_id=B.id left join ims_yq_haircircle_users C on A.sup_id=C.id WHERE ' . $where);
    //生成分页
    $pager = getPageHTML($total,$page,$pagesize);
    $sql = "select A.*,B.mobile fa_mobile,B.truename fa_truename,B.pid user_pid,C.pid sup_pid,C.mobile ch_mobile,C.truename ch_truename from ims_yq_haircircle_user_fx_log A left join ims_yq_haircircle_users B on A.user_id=B.id left join ims_yq_haircircle_users C on A.sup_id=C.id where $where order by A.id desc limit $start,$pagesize";

    $list = pdo_fetchall($sql);
    include $this->template('web/user_fx_log');
    exit;
}
